<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 5 Transitional//EN">
<%@ page pageEncoding="UTF-8" %>
<%@ page import="jp.co.technotree.apl.api.common.Message" %>
<%@ page import="jp.co.technotree.apl.cmd.rental.Ren1000Bean;" %>
<jsp:useBean id="formBean" class="jp.co.technotree.apl.cmd.rental.Ren1000Bean" scope="request" />
<%
	String userId = formBean.getUserId();
	String userNm = formBean.getUserNm();

    if(userNm == null) userNm="";

    Ren1000Bean.Record[] recordList = formBean.getRecordList();
    Ren1000Bean.UserRecord[] userRecordList = formBean.getUserRecordList();
    Ren1000Bean.KbnRecord[] kbnRecordList = formBean.getKbnRecordList();
%>
<html>
<head>


<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="apple-mobile-web-app-capable" content="yes"/>
<!-- 数字を電話番号にさせない -->
<meta name="format-detection" content="telephone=no"/>
<link rel='stylesheet' type='text/css' href='../../common/css/rental/ren1000.css' >
<script src="../../common/js/rental/ren1000.js" type="text/javascript"></script>
<script type='text/javascript' src='../../common/js/NumKeyBoard.js'></script>

<!-- ITEM-DROPDOWN START -->
<link rel="stylesheet" href="../../common/js/dropdown/dropdown.css" type="text/css">
<script src="../../common/js/dropdown/dropdown.js" type="text/javascript"></script>
<!-- ITEM-DROPDOWN END -->

<!--ポップアップ用-->
<link rel='stylesheet' type='text/css' href='../../common/css/popUp.css' >
<script type='text/javascript' src='../../common/js/popUp.js'></script>

<style type="text/css">
	.menu-img-rlist2000 {
		background:		url(../../common/img/menu/line.png) no-repeat;
	}

	.mainBtn {
		width: 150px;
		font-size:20px;
	}

	.div-wid {
		-webkit-overflow-scrolling:touch;
		height:415px;
		overflow:auto;
	}
	
	.TblField1{
		width:20px;
	}
	.TblField2{
		width:85px;
	}
	.TblField3{
		width:55px;
	}
	.TblField4{
		width:50px;
	}
	.TblField5{
		width:105px;
	}
	.TblField6{
		width:130px;
	}
	.TblField7{
		width:130px;
	}
	.TblField8{
		width:90px;
	}
	.TblField9{
		width:35px;
	}
	.TblField10{
		width:85px;
	}
	.TblField11{
		width:100px;
	}
	.ReadStyle{
		 background-color:#CCC;
	}
</style>



<script language='javascript'>

//画面固定
//document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);

function onInit(){
	<%if("1".equals(formBean.getErrMsgFlg())){%>
		alert_Custom('<%=Message.getMessage("WRN01060")%>');
	<%}%>
	//-------------------------------------------------------------------------
	//<!-- ITEM-DROPDOWN START -->
	var panel = document.getElementById("dropdown-panel");
	var input = document.getElementById("addTable");
	var targetList = getElementsByClassName(input,"input","item",true);
	
	dropdown = new CItemDropDownList(targetList,panel,"drop-contents");
	dropdown.setKeyUpEvent(text_onKeyUp);
	dropdown.setSelectEvent(list_onSelect);
	
	//
	dropdown.serverURL="../ren1001/ren1001";
	//<!-- ITEM-DROPDOWN END -->
	//-------------------------------------------------------------------------
	
	//-------------------------------------------------------------------------
	//<!-- NumKeyBoard START -->
	ProcStart	= new Date();
	
	clsNKB.init("NumKeyBoardID");
	//clsNKB.parentElement	= document.getElementById("BodyBlock");
	
	clsNKB.textFontSize		= 20;
	clsNKB.buttonFontSize	= 30;
	clsNKB.boxX				= -200;
	clsNKB.boxY				= 0;
	clsNKB.boxBalloonOffset	= 210;
	//<!-- NumKeyBoard END -->
	//-------------------------------------------------------------------------
}


function nextPageJump(nextPage){
	mainForm = document.getElementById("F1");
	document.getElementById("nextPage").value = nextPage;
	mainForm.submit();
}

//登録ボタンからの遷移
function insertPageJump(nextPage,dataId){
	mainForm = document.getElementById("F1");
	document.getElementById("nextPage").value = nextPage;
	document.getElementById("dataId").value = dataId;
	mainForm.submit();
}

//通常検索
function formSubmit() {
	var frm = document.main;
	if(frm.findDelvDtYear.value){
		if(frm.findDelvDtMonth.value){
			if(!(Number(frm.findDelvDtMonth.value) >= 1 && Number(frm.findDelvDtMonth.value) <= 12)){
				alert_Custom("<%=Message.getMessage("WRN00030").replace("$1","出庫日（月）")%>");
				return;
			}
		}
		//ソートクリア-----------------------
		frm.columnSortText.value = "";
		frm.columnSortSelect.value = "";
		//-----------------------------------
		frm.cmd.value = "cmd01";
		frm.submitFlag.value = "1";
		frm.submit();
	}else{
		alert_Custom("<%=Message.getMessage("WRN00010").replace("$1","出庫日（年）")%>");
		return;
	}
}
//ソート
function changeColumnSort(key) {
	var formName = "main";
	var frm = document[formName];
	frm.columnSortSelect.value = key;
	frm.submitFlag.value = "1";
	
	if(frm.findDelvDtYear.value){
		if(frm.findDelvDtMonth.value){
			if(!(Number(frm.findDelvDtMonth.value) >= 1 && Number(frm.findOdrDtMonth.value) <= 12)){
				alert_Custom("<%=Message.getMessage("WRN00030").replace("$1","出庫日（月）")%>");
				return;
			}
		}
		frm.cmd.value = "cmd01";
		frm.submitFlag.value = "1";
		frm.submit();
	}else{
		alert_Custom("<%=Message.getMessage("WRN00010").replace("$1","発注日（年）")%>");
		return;
	}
}

//-------------------------------------------------------------------------
//<!-- ポップアップ START -->

//パップアップ解除
function back(){
	document.getElementById("opAlertBtn").style.display = "none";
	document.getElementById("opAlert").style.display = "none";
	document.getElementById("opAlertButton").style.display = "none";
	document.getElementById("opAlertTop").style.display = "none";
	document.getElementById("allbackgr").style.display = "none";
}

//<!-- ポップアップ END -->
//-------------------------------------------------------------------------


//-------------------------------------------------------------------------
//<!-- ITEM-DROPDOWN START -->
var dropdown = null;

var inputDateTime = null;
var timerId = null;
var eventSrc={};
function text_onKeyUp(object,sender,evt){
	var value = sender.value;
	eventSrc.object = object;
	eventSrc.sender = sender;
	eventSrc.evt = evt;
	inputDateTime = new Date();
	//-----------------------------------------------
	//品番自動ハイフン「-」を付ける
	var chkLen=5;
	if(event.keyCode != 0008){
		//指定の桁以上ならスタート
		if(value.length>=chkLen){
			var hikaku = value.substring(chkLen, chkLen+1);
			if(hikaku != "-"){
				var frontValue = value.substring(0, chkLen);
				var backValue  = value.substring(chkLen, value.length);
				sender.value=frontValue+"-"+backValue;
			}
		}
	}
	//小文字を大文字へ
	sender.value = sender.value.toUpperCase();
	value = sender.value;
	//-----------------------------------------------
	if ( value.length >= <%=formBean.getGohoKensu() %> ){
		if ( evt.keyCode == 37 || evt.keyCode == 39 ){
			
		}else{
			if ( timerId == null ){
				// 連続送信防止
				timerId = window.setTimeout(function(){text_onTimeOut(object,sender,evt);},500);
			}
		}
	}
}

/**
* 一定時間入力が止まった場合に動作
*/
function text_onTimeOut(object,sender,evt){
	var nowDateTime = new Date();
	var lngTime = (nowDateTime.getTime()-inputDateTime.getTime());
	if ( lngTime >= 1000 ){
		timerId = null;
		xmlRequest(object,sender,evt);
	}else{
		timerId = window.setTimeout(function(){text_onTimeOut(eventSrc.object,eventSrc.sender,eventSrc.evt);},500);
	}
}

/**
* XML要求処理
*/
function xmlRequest(object,sender,evt){
	//alert(evt.keyCode);
	var table = document.getElementById("drop-contents");
	table.innerHTML="";
	
	var top = calculateOffsetTop(sender);
	var left = calculateOffsetLeft(sender);
	var height = sender.offsetHeight;
	var panel = document.getElementById("dropdown-panel");
	panel.style.top=top+height+"px";
	panel.style.left=left+"px";
	panel.style.display="block";
	
	var param="cate=ren1000&itemCd="+sender.value;
	
	var formName = "main";
	var frm = document[formName];
	var findDelvDtYear=frm.findDelvDtYear.value;
	var findDelvDtMonth=frm.findDelvDtMonth.value;
	
	if(findDelvDtYear!=""){
		 param+="&findDelvDtYear="+findDelvDtYear;
	}
	if(findDelvDtMonth!=""){
		 param+="&findDelvDtMonth="+findDelvDtMonth;
	}
	
	try {
		var frm = document.main;
		var objs = frm["invCate"];
		if (objs[1].checked == true){
			//仮入出庫
			param += "&afterProc=1";
		}
	} catch (e) {
		
	}

	object.doXmlRequest(object,sender,param);
}


/**
* リスト選択時コールバック処理
*/
function list_onSelect(object,sender,json){
	var panel = document.getElementById("dropdown-panel");
	panel.style.display="none";
	sender.focus();
	
	//----------
	var name=sender.name;
	var idx=name.substring(name.indexOf("[")+1,name.length-1);
	
	document.getElementById("findItemNo").value=json.itemcd;
	
}


function getElementsByClassName(parent,tagName,className,fullMatch){
	var i=0,j=0;
	var result = [], cnt = 0;
	var list = parent.getElementsByTagName(tagName);
	for ( i=0; i<list.length; i++ ){
		var name = list[i].className;
		if ( name ){
			var nameList = name.split(' ');
			for ( j=0; j<nameList.length; j++ ){
				if ( fullMatch ){
					if ( nameList[j] == className ){
						result[cnt++] = list[i];
					}
				}else{
					if ( nameList[j].indexOf(className) != -1 ){
						result[cnt++] = list[i];
					}
				}
			}
		}
	}
	return result;
}
function closeBtn(){
	var panel = document.getElementById("dropdown-panel");
	panel.style.display="none";
} 
//----------------------------------------------------------------------

//-------------------------------------------------------------------------
//<!-- NumKeyBoard START -->
var		clsNKB			= new CNumKeyBoard();

//=================================================================
//	データ入力後の処理
//=================================================================
function afterInputData(obj) {
	var frm = document.forms.main;
	var parent_node = obj.parentNode;
	for(var i = 0; i < 2; i++) {
		if(parent_node.className == "ItemLine") {
			break;
		}
		parent_node = parent_node.parentNode;
	}
	var child_nodes = parent_node.getElementsByTagName("INPUT");
	for(var i = 0; i < child_nodes.length; i++) {
		if(child_nodes[i].className == "DetailStart") {
			// 開始時間の設定
			if(child_nodes[i].value == "") {
				child_nodes[i].value = FieldStart;
			}
		}
		if(child_nodes[i].className == "DetailEnd") {
			// 終了時間の設定
			child_nodes[i].value = frm.NowTime.value;
		}
		if(child_nodes[i].className == "DetailTime") {
			// 作業時間の設定
			child_nodes[i].value = convStrToNum(child_nodes[i].value) + Math.round(PassTime(new Date(FieldStart)) / 1000);
		}
		if(child_nodes[i].className == "InputChanged") {
			// 行変更フラグを設定
			child_nodes[i].value = "1";
		}
		if (child_nodes[i].className.match(/DetailDate/i)) {
			// 日付の設定
			child_nodes[i].value = delComma(child_nodes[i].value);
		}
	}
}
//--------------------------------
//カンマ削除関数
//--------------------------------
function delComma(w) {
    var z = w.replace(/,/g,"");
    return (z);
}

//--------------------------------
//	型変換 String→Numeric
//--------------------------------
function convStrToNum(strVal) {
	var cnv = Number(strVal);
	var res = 0;
	if(isNaN(cnv)) {
		// 数値じゃない!
	} else {
		res = cnv;
	}
	return res;
}
//<!-- NumKeyBoard END -->
//----------------------------------------------------------------------

//クリアボタン
function findClearBtn(){
	location.href = "../ren1000/ren1000";
}
</script>


</head>

<body onLoad="onInit()">
<form name="main" id="F1" action="./ren1000" method="post" class="frmMain"  onsubmit="return false;">
<div id="NumKeyBoardID"></div>
<input type="hidden" name="cmd" value="cmd01">
<input type="hidden" name="submitFlag" value="0">
<input type="hidden" id="nextPage" name="nextPage" value="">
<input type="hidden" id="dataId" name="dataId" value="">
<!-- カラムソート -->
<input type="hidden" name="columnSortText" value="<%=formBean.getColumnSortText()%>">
<input type="hidden" name="columnSortSelect" value="">
<table style="">
	<!--HEADER TITLE START -->
	<tr style = "background-color:#e1e1e1;  font-weight: bold;  border-bottom:1px solid #e1e1e1; background: -webkit-gradient(linear, left top, left bottom, from(#e1e1e1), to(#ffffff));　 ">
		<td colspan="2" class ="header_tbl" style = "font-size:22px; height:40px;"  align = "left">
			　予備品管理システム (<%=formBean.kojou%>)　　　
			<span style="font-size:30px; text-shadow:2px 2px #666; 	color:#aaa;">修理・貸出一覧画面<%=userNm%></span>
		</td>
	</tr>
	<!--HEADER TITLE END -->

	<!--予備品選択画面　START  -->
	<!-- 検索部  -->
	<tr style="height:628px;vertical-align:top;">
		<td class="right" >
			<!-- <div class="mainLine" id = "mainLine" style="display:inline; " ></div> -->


			<table class="searchTbl" id="addTable" name="addTable" >
				<tr>
					<td>
						表示区分：
					</td>
					<td>
						<input type="text" name="status" id="status" class="inputStyle ReadStyle" style="width:120px;color: black;" value="<%=formBean.getStatusKbn()%>" readonly>
					</td>
					<td >
						出庫日
						<br>(年度)：
					</td>
					<td>
						<input type="text" class="DetailDate inputStyle" style="width:50px;" name="findDelvDtYear" value="<%=formBean.getFindDelvDtYear()%>" onclick='clsNKB.setNumKeyBoard(this, 4, 0, true, 200);' onChange='afterInputData(this);' readonly>年
						<input type="text" class="DetailDate inputStyle" style="width:50px;" name="findDelvDtMonth" value="<%=formBean.getFindDelvDtMonth()%>" onclick='clsNKB.setNumKeyBoard(this, 2, 0, true, 200);' onChange='afterInputData(this);' readonly>月
					</td>
					<td colspan="3">
					</td>
					<td>
						<input onclick="findClearBtn();" type="button" value="クリア" class="button">
					</td>
				</tr>
				<tr>
					<td>
						担当：
					</td>
					<td>
						<select name="findDelvUsr" class="selectStyle" style="width:160px;">
						<option value=""></option>
						<%
							if ( userRecordList!=null) {
								for (int i=0; i<userRecordList.length; i++) {
									Ren1000Bean.UserRecord userRecord=userRecordList[i];
						%>
							<option value="<%=userRecord.userId%>" <%=userRecord.userId.equals((formBean.getFindDelvUsr())) ? " selected " : "" %>>
								<%=userRecord.userNm%>
							</option>
						<%
								}
							}
						%>
						</select>
					</td>
					<td >
						Y品番：
					</td>
					<td>
						<input id="findItemNo" type="text" class="item inputStyle" style="width:120px;" name="findItemNo" value="<%=formBean.getFindItemNo()%>" maxlength="11">
					</td>
					<td>
						出庫区分：
					</td>
					<td>
						<select name="findDelvDiv" class="selectStyle" style="width:110px;">
						<option value="">全て</option>
						<%
							if ( kbnRecordList!=null) {
								for (int i=0; i<kbnRecordList.length; i++) {
									Ren1000Bean.KbnRecord kbnRecord=kbnRecordList[i];
						%>
							<option value="<%=kbnRecord.valueId%>" <%=kbnRecord.valueId.equals((formBean.getFindDelvDiv())) ? " selected " : "" %>>
								<%=kbnRecord.valueNm%>
							</option>
						<%
								}
							}
						%>
						</select>
					</td>
					<td style="width:120px;">
						<input onclick="formSubmit();" type="button" value="検索" class="button">
					</td>
					<td style="width:120px;">
						<input onclick="nextPageJump('top1000');" type="button" value="戻る" class="button">
					</td>
				</tr>
			</table>
			
			<br>
			<hr width="95%" size="1" color="#000000">
			<%if(recordList.length >= 50){%>
				&nbsp;&nbsp;&nbsp;
				<span style="color:blue;"><%=Message.getMessage("INF00050")%></span>
			<%}else{%>
				<br>
			<%}%>

<%if("1".equals(formBean.getSubmitFlag())){%>
			<!-- 一覧部  -->
			<table class="listTbl" >
				<tr>
					<th class="TblField1">&nbsp;</th>
					<th class="TblField2" onclick="changeColumnSort('trrp.delv_dt');">出庫日	<%=formBean.getSort().getSortText("trrp.delv_dt")%></th>
					<th class="TblField3" onclick="changeColumnSort('mu.usr_nm');">担当		<%=formBean.getSort().getSortText("mu.usr_nm")%></th>
					<th class="TblField4" onclick="changeColumnSort('trrp.delv_div');">区分	<%=formBean.getSort().getSortText("trrp.delv_div")%></th>
					<th class="TblField5" onclick="changeColumnSort('item_no');">Y品番		<%=formBean.getSort().getSortText("item_no")%></th>
					<th class="TblField6" onclick="changeColumnSort('mrs.item_nm');">品名		<%=formBean.getSort().getSortText("mrs.item_nm")%></th>
					<th class="TblField7" onclick="changeColumnSort('mrs.model');">型式			<%=formBean.getSort().getSortText("mrs.model")%></th>
					<th class="TblField8" onclick="changeColumnSort('delv_site_nm');">出庫先	<%=formBean.getSort().getSortText("delv_site_nm")%></th>
					<th class="TblField9" onclick="changeColumnSort('delv_num');">出庫	<%=formBean.getSort().getSortText("delv_num")%></th>
					<th class="TblField10" onclick="changeColumnSort('trrt.ret_dt');">返却日		<%=formBean.getSort().getSortText("trrt.ret_dt")%></th>
					<th class="TblField11">&nbsp;</th>
				</tr>

			</table>
			<div class="div-wid ">
			<table class="listTbl" >
<%
		if ( recordList!=null) {
			if ( recordList.length == 0 ){
%>			
			<tr height="120px">
				<td colspan="12">データが存在しません。</td>
			</tr>
<%			
			}
			for (int i=0; i<recordList.length; i++) {
				Ren1000Bean.Record record=recordList[i];
				//担当者のスプリット
				String usrNm = record.usrNm;
				String[] strUsrNm = usrNm.split("\\s+");;
				if(strUsrNm.length > 1){
					usrNm = strUsrNm[0];
				}
%>
				<tr>
					<td class="TblField1 txtCenter" onclick="opInf.mhClick(this);">
						<%=i+1%>
						<input type="hidden" name="lblField1" value="<%=record.delvDt%>" >
						<input type="hidden" name="lblField2" value="<%=record.usrNm%>" >
						<input type="hidden" name="lblField3" value="<%=record.delvDivKbn%>" >
						<input type="hidden" name="lblField4" value="<%=record.itemNo%>">
						<input type="hidden" name="lblField5" value="<%=record.itemNm%>" >
						<input type="hidden" name="lblField6" value="<%=record.model%>" >
						<input type="hidden" name="lblField7" value="<%=record.delvSiteNm%>" >
						<input type="hidden" name="lblField8" value="<%=record.delvNum%>" >
						<input type="hidden" name="lblField9" value="<%=record.retDt%>" >
						<input type="hidden" name="lblField10" value="<%=record.delvNo%>" >
					</td>
					<td class="TblField2" onclick="opInf.mhClick(this);"><%=record.delvDt%></td>
					<td class="TblField3" onclick="opInf.mhClick(this);"><%=usrNm%></td>
					<td class="TblField4" onclick="opInf.mhClick(this);"><%=record.delvDivKbn%></td>
					<td class="TblField5" onclick="opInf.mhClick(this);">
							<%=record.itemNo%>
					</td>
					<td class="TblField6" onclick="opInf.mhClick(this);"><%=record.itemNm%></td>
					<td class="TblField7" onclick="opInf.mhClick(this);"><%=record.model%></td>
					<td class="TblField8" onclick="opInf.mhClick(this);"><%=record.delvSiteNm%></td>
					<td class="TblField9 txtRight" onclick="opInf.mhClick(this);"><%=record.delvNum%></td>
					<td class="TblField10" onclick="opInf.mhClick(this);"><%=record.retDt%></td>
					<td class="TblField11"><input type="button" value="返却" class="button" onclick="insertPageJump('ren3000','<%=record.delvNo%>');"></td>
				</tr>
<% 	
			}
		}
%>

			</table>
			</div>
<%}%>

			<!--ログインMAIN画面　END  -->
		</td>
	</tr>
</table>
	<div class='footer' align='right' style="font-size:35px; background-image: url(../../common/img/toyotaB.png); background-repeat: no-repeat; align:top;" ></div>


	<!-- 詳細用 -->
	<div class="opBoardBtn" id = "opBoardBtn" style="display:none;" ></div>
	<div class="opBoardInf" id = "opBoardInf" style="display:none;" ></div>
	<div class="opBoardButtom" id = "opBoardButtom" style="display:none;"></div>
	<div class="opBoardTop" id = "opBoardTop" style="display:none; font-size:22px;">　詳細情報　</div>
	<div class="opBoard" id = "opBoard"  style="display:none; overflow: scroll;"></div>
	<div class="mhBoard" id = "mhBoard" style="display:none;"></div>


<!-- ITEM-DROPDOWN START -->
<div class="dropdown-panel" id="dropdown-panel">
	<div class="dropdown-panel-in">
		<div class="header">
			<div style="float:left;width:110px;height:20px;">
				<table border=0>
					<tr>
						<td style="width:110px;height:20px;">品番</td>
					</tr>
				</table>
			</div>
			<div style="float:right;width:40px;text-align:right;">
				<button class="closebtn" type="button" onClick="closeBtn();" style="width:18px;height:17px; padding:0px;">
					<img src="../../common/js/dropdown/close.gif" alt="閉じる">
				</button>
			</div>
		</div>
		<div class="drop-contents" id="drop-contents">
		</div>
		<div class="footer"></div>
	</div>
</div>
<!-- ITEM-DROPDOWN END -->

	<!--警告 ポップアップ---------------------------------------------------------------------------- -->
	<div id="allbackgr" class="allbackgr" style="display:none;"></div>
	<div class="opAlertBtn" id = "opAlertBtn" style="display:none;" ></div>
	<div class="opAlertButton" id = "opAlertButton" style="display:none;" ></div>
	<div class="opAlertTop" id = "opAlertTop" style="display:none; font-size:22px;">　予備品管理システム　</div>
	<div class="opAlert" id = "opAlert" style="display:none;"></div>
	<!-- -------------------------------------------------------------------------------------------- -->
</form>
</body>
</html>
